#include <iostream>
#include <fstream>
#include "Bellman-Ford.h"

using namespace std;

int main()
{
    int numberOfVertexes = 0;
    int numberOfEdges = 0;
    int from = 0, to = 0, weight = 0;

	ifstream F;
	F.open("input.txt");

    F >> numberOfVertexes >> numberOfEdges;
    CGraph<int, int> graph(0, 0, numberOfVertexes);

    for (int i = 0; i < numberOfVertexes; ++i)
    {
        graph.addVertexWeight(i, 1);
    }

    for (int i = 0; i < numberOfEdges; ++i)
    {
        F >> from >> to >> weight;
        graph.addEdge(from - 1, to - 1, weight);
    }

    CFordBellman<CGraph<int, int> > fb(graph, graph.GetVertexListBegin());
    fb.Process();

    map<CGraph<int, int>::CVertexIterator, int> m = fb.GetMinPathWeights();

    vector<int> results(numberOfVertexes, 30000);

    for (auto it = m.begin(); it != m.end(); ++it)
    {
        results[((*it).first).GetIndexOfCurrentVertex()] = (*it).second;
    }

    for (auto i:results)
    {
        cout << i << " ";
    }

    return 0;
}
